package org.springside.examples.showcase.utilities.wb;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import org.apache.commons.lang.StringUtils;
import org.apache.http.HttpException;
import org.springside.modules.utils.HttpUtils;

/**
 * 新浪微博采集
 */
public class SinaCrawler {
	/**
	 * "/1630461754/yyaMTDuhU"
	 */
	public static String getWbContents(String url, String headinfo) {
		try {
			String cookie = SinaLoginSha1.getCookie();
			List reqResult = null;
			List<String> headers = new ArrayList<String>();
			headers.add("Accept:*/*");
			headers.add("Accept-Language:zh-cn");
			headers.add("Connection:Keep-Alive");
			headers.add("Host:weibo.com");
			headers.add("Cookie:" + cookie);
			if (!StringUtils.isEmpty(headinfo)) {
				String[] _headers = headinfo.split("\\;");
				for (String head : _headers) {
					headers.add(head);
				}
			}
			headers.add("User-Agent:Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; .NET CLR 2.0.50727)");
			HttpUtils httpUtils2 = new HttpUtils("weibo.com", 80, 60000, 60000, headers);
			reqResult = httpUtils2.doRequest("GET", url, null);
			return (String) reqResult.get(1);
		} catch (HttpException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
		return null;
	}

	public static void main(String[] args) {
		String wbContents = SinaCrawler.getWbContents("/1793000440/yDHrmjr3S", "");
		System.out.println(wbContents);
	}
}
